home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / funstat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  2.4 KB  |  73 lines

  1. /*
  2. \funcref{fun\_stat}{void fun\_stat ()}
  3.     {}
  4.     {}
  5.     {}
  6.     {fun\_exec()}
  7.     {funsyste.c}
  8.     {
  9.  
  10.         This function expects a filename as last pushed {\em e\_str}
  11.         value. The file attributes are retrieved by a {\em stat ()} call and
  12.         the return register is set to the type {\em e\_list}. This list
  13.         returns the following information:
  14.  
  15.         \begin{itemize}
  16.  
  17.             \item The first element represents the file attributes.
  18.  
  19.             \item The second element represents the file size.
  20.  
  21.         \end{itemize}
  22.  
  23.     }
  24. */
  25.  
  26. #include "icm-exec.h"
  27.  
  28. void fun_stat ()
  29. {
  30.     register char
  31.         *fname;                                 /* file name */
  32.     register int
  33.         fileatt = 0,                            /* file attributes */
  34.         mode;                                   /* P_CHECK wanted? */
  35.     char
  36.         buf [80];                               /* conversion buf */
  37.     struct stat
  38.         statbuf;                                /* file stat buffer */
  39.  
  40.     mode = stack [sp].vu.intval;                /* get mode arg */
  41.     fname = stack [sp - 1].vu.i->ls.str;        /* get file name */
  42.     reg = newvar (e_list);                      /* return result as list */
  43.  
  44.     if (stat (fname, &statbuf))                 /* do stat call */
  45.     {                                           /* failure to stat? */
  46.         if (P_CHECKMODE (mode))                 /* if mode indicates abort..*/
  47.             error ("stat - unable to stat "
  48.                    "file %s", fname);
  49.         else
  50.             return;                             /* no checking: return */
  51.     }                                           /* empty list */
  52.  
  53.     if (statbuf.st_mode & S_IREAD)              /* set file attribute int */
  54.         fileatt |= IS_IREAD;
  55.     if (statbuf.st_mode & S_IWRITE)
  56.         fileatt |= IS_IWRITE;
  57.     if (statbuf.st_mode & S_IEXEC)
  58.         fileatt |= IS_IEXEC;
  59.     if (statbuf.st_mode & S_IFDIR)
  60.         fileatt |= IS_IFDIR;
  61.     if (statbuf.st_mode & S_IFCHR)
  62.         fileatt |= IS_IFCHR;
  63.     if (statbuf.st_mode & S_IFREG)
  64.         fileatt |= IS_IFREG;
  65.  
  66.     sprintf (buf, "%u", fileatt);               /* file attr --> string */
  67.     reg = addtolist (reg, buf);                 /* = element #0 */
  68.  
  69.     sprintf (buf, "%ld",                        /* file size --> string */
  70.         (long) statbuf.st_size);                /* = element #1 */
  71.     reg = addtolist (reg, buf);
  72. }
  73.